
#include "settingsadapter.h"

#include <QSettings>

SettingsAdapter::SettingsAdapter(QObject *parent)
 	 : QObject(parent)
{
}

SettingsAdapter::~SettingsAdapter()
{
}

QString SettingsAdapter::getValueFor(const QString &objectName, const QString &defaultValue)
{
    QSettings settings;

    // If no value has been saved, return the default value.
    if (settings.value(objectName).isNull()) {
        return defaultValue;
    }

    // Otherwise, return the value stored in the settings object.
    return settings.value(objectName).toString();
}

void SettingsAdapter::saveValueFor(const QString &objectName, const QString &inputValue)
{
    // A new value is saved to the application settings object.
    QSettings settings;
    settings.setValue(objectName, QVariant(inputValue));
}

bool SettingsAdapter::getShuffle()
{
	QString shuffle = getValueFor("shuffle", "false");
	return shuffle.compare("true") == 0;
}
void SettingsAdapter::setShuffle(bool shuffle)
{
	QString sshuffle = shuffle ? "true" : "false";
	saveValueFor("shuffle", sshuffle);
}
bool SettingsAdapter::getRepeat()
{
	QString repeat = getValueFor("repeat", "false");
	return repeat.compare("true") == 0;
}
void SettingsAdapter::setRepeat(bool repeat)
{
	QString srepeat = repeat ? "true" : "false";
	saveValueFor("repeat", srepeat);
}
